<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>系统通知</title>
    <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport"/>
    <meta content="yes" name="apple-mobile-web-app-capable"/>
    <meta content="black" name="apple-mobile-web-app-status-bar-style"/>
    <meta content="telephone=no" name="format-detection"/>
    <script src="/js/plugins/jquery/jquery.min.js"></script>
    <script src="/js/plugins/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css">
    <link rel="stylesheet" href="/css/reset.css"/>
    <link href="../css/systemMessage.css" rel="stylesheet" type="text/css"/>
    <script>
        $(function () {
            var user = JSON.parse(sessionStorage.getItem("user"));
            var userId = user.id;
            //首先我们需要获取当前页的标签
            var currentInput = $('#currentPage');
            //因为我们手机滚动之前的数据就没有了,只有当前查出来的不合理
            var arr = [];
            var pages = 1;

            function query() {
                //获取当前页
                var currentPage = currentInput.val();
                $.get('/allMessages/' + userId, {currentPage: currentPage}, function (data) {
                    console.log(data);
                    pages = data.systemMessagePageInfo.pages;
                    console.log(pages);
                    //把两个数组的数据合并在一起,就可以滚动了
                    $.merge(arr, data.systemMessagePageInfo.list);
                    var json = {list: arr};
                    console.log(json);
                    $('.aui-scrollView').renderValues(json, {
                        getHref: function (item, value) {
                            var href = $(item).data("href");
                            $(item).attr("href", href + value);
                        }
                    });
                });
                currentInput.val(parseInt(currentPage) + 1);
            }

            query();
            $('._j_add_more_button').click(function () {
                var currentPage = currentInput.val();
                if (currentPage <= pages) {
                    query();
                } else {
                    $(document).dialog({
                        type: 'notice',
                        infoText: '没有更多消息了!!!',
                        autoClose: 1000
                    });
                }
            })
        })
    </script>
</head>
<body>
<input type="hidden" id="currentPage" name="currentPgee" value="1">
<section class="aui-flexView">
    <header class="aui-navBar aui-navBar-fixed">
        <a href="/mine/message.html" class="aui-navBar-item">
            <i class="icon icon-return"></i>
        </a>
        <div class="aui-center">
            <span class="aui-center-title">系统通知</span>
        </div>
        <a href="javascript:;" class="aui-navBar-item">
            <i class="icon icon-sys"></i>
        </a>
    </header>
    <section class="aui-scrollView">
        <div class="aui-service-box" render-loop="list">
            <div>
                <div class="aui-service-circle">
                    <span render-html="list.sentTime"></span>
                </div>
                <div class="aui-service-list">
                    <h3 render-html="list.travel.title"></h3>
                    <a data-href="/travelContent.html?id="  render-key="list.travel.id" render-fun="getHref" class="aui-news-item">
                        <div class="aui-news-item-hd">
                            <img render-src="list.travel.coverUrl" alt="">
                        </div>
                        <div class="aui-news-item-bd">
                            <p render-html="list.stateText"></p>
                        </div>
                    </a>
                </div>
            </div>
        </div>
        <div class="aui-news-box" style="text-align: center">
            <a class="more-list _j_add_more_button">更多消息</a>
        </div>
    </section>
</section>

</body>
</html>
